package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.Content;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.PetclassificationBean;
import com.example.myapplication.hospital.MedicActivity;

import java.util.List;

public class PetclassificationApter extends  RecyclerView.Adapter<PetclassificationApter.Myhot>{
    private Context context;
    private List<PetclassificationBean.DataBean> list;

    public PetclassificationApter(Context context, List<PetclassificationBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_petclassification, null);
        return new PetclassificationApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull Myhot holder, int position) {
        Glide.with(context).load(TokenBean.IP+list.get(position).getImgUrl()).into(holder.img);
        holder.text.setText(list.get(position).getName());
        //医生页面
        holder.re_medic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MedicActivity.class);
                intent.putExtra(Commom.REGISTRATION_ID,String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final TextView text;
        private final ImageView img;
        private final RelativeLayout re_medic;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            text = itemView.findViewById(R.id.text);
            re_medic = itemView.findViewById(R.id.re_Medic);
        }
    }
}
